package edu.usc.csci578.model;

import java.util.ArrayList;
import java.util.List;

import edu.usc.csci578.util.ModelParser;

public class SClass {
	private String name;
	private String packageName;
	private List<SMethod> methods;
	private boolean isJava;

	public SClass(String name) {
		init(name, "");
	}

	public SClass(String name, String packageName) {
		init(name, packageName);
	}

	private void init(String name, String packageName) {
		this.name = name;
		this.packageName = packageName;
		isJava = ModelParser.parseIsJave(packageName);
		methods = new ArrayList<SMethod>();
	}

	public void setPackageName(String name) {
		this.packageName = name;
		isJava = ModelParser.parseIsJave(packageName);
	}

	public String getName() {
		return name;
	}

	public String getPackageName() {
		return packageName;
	}

	public String getUniqueName() {
		if (packageName.equals("")) {
			return name;
		}
		return this.packageName + "." + this.name;
	}

	public boolean add(SMethod method) {
		if (method != null && !methods.contains(method)) {
			methods.add(method);
			return true;
		}
		return false;
	}

	public List<SMethod> getMethods() {
		return methods;
	}

	public String toString() {
		StringBuffer output = new StringBuffer();
		output.append("Class Name: ");
		output.append(this.name);
		output.append("\nPackage: ");
		output.append(this.packageName);
		output.append("\nmethod:\n");
		for (SMethod method : methods) {
			output.append(method);
		}
		output.append("\n");
		return output.toString();
	}

	public boolean isJava() {
		return isJava;
	}
}
